project(boot LANGUAGES ASM)

# -m 参数是指定目标架构
# --section-start 定义二进制文件中的符号的地址
# -o 指定输出文件的格式
set(CMAKE_EXE_LINKER_FLAGS "-m elf_i386 -Ttext=0x7c00  --section-start boot_end=0x7dfe")
set(CMAKE_ASM_LINK_EXECUTABLE "${LINKER_TOOL} <OBJECTS> ${CMAKE_EXE_LINKER_FLAGS} -o ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf")

file(GLOB FILE_LIST "*.h" "*.c")
add_executable(${PROJECT_NAME} Boot.S)

add_custom_command(TARGET ${PROJECT_NAME} 
    POST_BUILD 
    COMMAND ${OBJCOPY} -O binary ${PROJECT_NAME}.elf ${CMAKE_SOURCE_DIR}/bin/${PROJECT_NAME}.bin
    COMMAND ${OBJDUMP} -x -d -S -m i8086 ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf > ${CMAKE_SOURCE_DIR}/obj/${PROJECT_NAME}_dis.txt
    COMMAND ${READELF} -a ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.elf > ${CMAKE_SOURCE_DIR}/obj/${PROJECT_NAME}_elf.txt
    )